﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ThuVienCT;
using System.Data.SqlClient;

namespace QLCTNA
{
    public partial class Fr_Main : Form
    {
        private ConnectionData cnn = null;
        public Fr_Main()
        {
            InitializeComponent();
            FileText ft = new FileText("Config\\Config.ini");

            this.MaximizeBox = false;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            cnn = Connection.Connect();
        }

        private void Fr_Main_Load(object sender, EventArgs e)
        {
            fr_ĐăngNhập frm = new fr_ĐăngNhập();
            frm.ShowDialog();
       

        }

        private void tạoMớiCôngThứcNấuĂnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Frm_taomoi taomoi = new Frm_taomoi();
            taomoi.ShowDialog();
            Fr_Main Main = new Fr_Main();
            Main.Hide();
        }

        private void quảnLýCôngThứcNấuĂnToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void hiệnThịCôngThứcNấuĂnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Frm_hienthi hienthi = new Frm_hienthi();
            hienthi.ShowDialog();
        }


        private string str = "***CHƯƠNG TRÌNH QUẢN LÝ CÔNG THỨC NẤU ĂN ***";
        int i = 0;
        private string str2;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (i < str.Length)
            {
                str2 += str[i];
                lblchuongtrinh.Text = str2;
                lblchuongtrinh.RightToLeft += 2;
                i++;
            }
            else
            {
                i = 0;
                str2 = "";
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
            int dong;
           
            {

                dong = e.RowIndex;
                txtma.Text = dgvmain.Rows[dong].Cells[0].Value.ToString();
                txtten.Text = dgvmain.Rows[dong].Cells[1].Value.ToString();
              
            }
            
           
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void treeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string select = null;
           int check = 0;

           if (e.Node.Text == "Món Kho")
           {
               select = " select * from vw_congthuc where [Phân Loại]='" + e.Node.Text + "'";
               check = cnn.Execute(select);
               dgvmain.DataSource = cnn.SelectTable(select);
           }

            if (e.Node.Text=="Món Xào" )
            {
                select = " select * from vw_congthuc where [Phân Loại]='" + e.Node.Text+ "'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text== "Món Nướng")
            {
              select = " select * from vw_congthuc where [Phân Loại]=N'Món Nướng'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Món Trộn ")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Món Trộn'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Món Chiên")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Món Chiên'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Món Hấp")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Món Hấp'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Món Xốt")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Món Xốt'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Món Hầm")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Món Hầm'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Súp/Cháo")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Súp/Cháo'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
            if (e.Node.Text == "Gỏi/Cuốn")
            {
                select = " select * from vw_congthuc where [Phân Loại]=N'Gỏi/Cuốn'";
                check = cnn.Execute(select);
                dgvmain.DataSource = cnn.SelectTable(select);

            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void btntimkiem_Click(object sender, EventArgs e)
        {
            string tk="select * from vw_congthucnauan where [Tên Công Thức] like N'%"+@txttimkiem.Text+"%'";
            cnn.SelectTable(tk);
            dgvmain.DataSource = cnn.SelectTable(tk);
        }

        private void dataGriview1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int dong;

            dong = e.RowIndex;
          
            txtma.Text = "";
            txtten.Text = "";
           
            lblmapl.Text = dgvmain.Rows[dong].Cells[0].Value.ToString();
            lbltenpl.Text = dgvmain.Rows[dong].Cells[1].Value.ToString();
            lblpl.Text = dgvmain.Rows[dong].Cells[2].Value.ToString();

        }

    }
}